﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/Static/demo.css" rel="stylesheet" type="text/css" />
    <script src="/Static/boot.js" type="text/javascript"></script>
    <link href="/Static/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 90%;">
                    <label style="font-family: Verdana;">
                        所属分类：
                    </label>
                    <input id="partsCatrgoryID" name="partsCatrgoryID" class="mini-buttonedit" onbuttonclick="onSelectCategory" allowinput="false" width="100px"
                           required="true" />
                    <label style="font-family: Verdana;">
                        所属供应商：
                    </label>
                    <input id="partsSupplierID" name="partsSupplierID" class="mini-buttonedit" onbuttonclick="onSelectPartsSupplier" allowinput="false" width="100px"
                           required="true" />
                    <label style="font-family: Verdana;">
                        适用型号：
                    </label>
                    <input id="partsModelID" name="partsModelID" class="mini-buttonedit" onbuttonclick="onSelectModel" allowinput="false" width="100px"
                           required="true" />
                    <label style="font-family: Verdana;">
                        配件名称：
                    </label>
                    <input class="mini-textbox" id="txt_KeyValue" />
                    <label style="font-family: Verdana;">
                        是否启用：
                    </label>
                    <input name="IsActive" class="mini-combobox" textfield="text" valuefield="id" emptytext="请选择..."
                           value="" allowinput="false" shownullitem="true" url="/ConfigData/IsActive.txt" nullitemtext="请选择..." />
                    <label style="font-family: Verdana;">
                        Wisetech 料号：
                    </label>
                    <input class="mini-textbox" id="txt_WisetechPartsNO" width="100px" />
                    <br />
                    <label style="font-family: Verdana;">
                        供应商料号：
                    </label>
                    <input class="mini-textbox" id="txt_SupplierPartsNO" width="100px" />
                    采购价格：
                    <input class="mini-textbox" id="txt_ProcurementPriceStart" width="100px" vtype="float" />
                    -<input class="mini-textbox" id="txt_ProcurementPriceEnd" width="100px" vtype="float" />
                    销售价格：
                    <input class="mini-textbox" id="txt_MarketPriceStart" width="100px" vtype="float" />
                    -<input class="mini-textbox" id="txt_MarketPriceEnd" width="100px" vtype="float" />
                    库存数量：
                    <input class="mini-textbox" id="txt_StockQuantityStart" width="100px" vtype="float" />
                    -<input class="mini-textbox" id="txt_StockQuantityEnd" width="100px" vtype="float" />
                    <a class="mini-button" iconcls="icon-search" onclick="searchList()">查询</a> <a class="mini-button"
                                                                                                  iconcls="icon-remove" onclick="clear()">清空条件</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconcls="icon-add" onclick="Add()" plain="true">增加</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-edit" onclick="Edit()" plain="true">编辑</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-remove" onclick="Remove()">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-reload" onclick="reloadData()" plain="true">刷新</a>
                    <a class="mini-button" id="btnExportExcel" onclick="ExportExcel()">导出Excel</a>
                </td>
            </tr>
        </table>
    </div>
    <!--onrowdblclick="Edit"-->
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 80%;" url="/Ajax/AjaxService.aspx?method=GetPartsList&sordOrder=DESC" multiselect="true" 
         idfield="ID" sizelist="[5,10,15,20,50]" pagesize="15" showcolumnsmenu="true" onrowclick="onShowRowDetail">
        <div property="columns">
            <div type="checkcolumn" width="20">
            </div>
            <div type="indexcolumn" width="15">
            </div>
            <div field="CategoryDisplayName" width="50" headeralign="center" align="center" allowsort="true">
                所属分类
            </div>
            <div field="SupplierName" width="50" headeralign="center" align="center" allowsort="true">
                供应商名称
            </div>
            <div field="WisetechPartsNO" width="80" headeralign="center" align="center" allowsort="true">
                Wisetech料号
            </div>
            <div field="SupplierPartsNO" width="50" headeralign="center" align="center" allowsort="true">
                供应商料号
            </div>
            <div field="PartsName" width="50" headeralign="center" align="center" allowsort="true">
                配件名称
            </div>
            <div field="PartsDisplayName" width="50" headeralign="center" align="center" allowsort="true">
                配件显示名称
            </div>
            <!--<div field="MaterialSpecification" width="50" headeralign="center" align="center" allowsort="true">
                材料及规格
            </div>-->
            <div field="ProcurementPrice" width="50" headeralign="center" align="center" allowsort="true">
                采购价格
            </div>
            <!--<div field="ProcurementCurrency" width="50" headeralign="center" align="center" allowsort="true">
                    采购货币
                </div>-->
            <div field="MarketPrice" width="50" headeralign="center" align="center" allowsort="true">
                销售价格
            </div>
            <!--<div field="MarketCurrency" width="50" headeralign="center" align="center" allowsort="true">
                    销售货币
                </div>-->
            <div field="GetGoodsDays" width="50" headeralign="center" align="center" allowsort="true">
                交期(天)
            </div>
            <div field="PayGoodsDays" width="50" headeralign="center" align="center" allowsort="true">
                帐期(天)
            </div>
            <div field="StockQuantity" width="50" headeralign="center" align="center" allowsort="true">
                库存
            </div>
            <div field="LeastSellCount" width="50" headeralign="center" align="center" allowsort="true">
                最小出售数量
            </div>
            <div field="IsAvailable" width="50" headeralign="center" align="center" allowsort="true">
                状态
            </div>
        </div>
    </div>
    <div id="PartsModelForm" style="display: none; width: 97%; margin: 0px,5px,0px,15px;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            height: 100%" selectonload="true">
        <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
            <table style="width: 95%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="addModel">添加适用型号</a> <a class="mini-button"
                                                                                                   iconcls="icon-cancel" onclick="DelModel">删除适用型号</a>
                        <a class="mini-button" iconcls="icon-redo" onclick="HideDetail">关闭明细</a>
                    </td>
                    <!--<td style="white-space:nowrap;">
                            查询用户:  <input id="txt_User" class="mini-textbox"  style="width:150px;" />
                            <a class="mini-button" onclick="searchUser()">查询</a>
                        </td>-->

                </tr>
            </table>
        </div>
        <div id="PartsModelGrid" class="mini-datagrid" style="width: 100%; height: 150px;"
             url="/Ajax/AjaxService.aspx?method=GetPartsModelMappingList" multiselect="true" allowresize="false"
             showvgridlines="true" showpager="false" showcolumnsmenu="true">
            <div property="columns">
                <div type="checkcolumn" width="20">
                </div>
                <div type="indexcolumn" width="20" headeralign="center" align="center">
                    序
                </div>
                <div field="BrandsDisplayName" width="50" headeralign="center" align="center" allowsort="true">
                    所属品牌显示名称
                </div>
                <div field="ModelName" width="50" headeralign="center" align="center" allowsort="true">
                    型号名称
                </div>
                <div field="ModelDisplayName" width="100" headeralign="center" align="center" allowsort="true">
                    型号显示名称
                </div>
            </div>
        </div>
    </div>
    <!--导出Excel相关HTML-->
    <form id="excelForm" action="/Ajax/export.aspx?type=Parts" method="post" target="excelIFrame">
        <input type="hidden" name="columns" id="excelData" />

        <input type="hidden" name="keyValue" id="txt_KeyValueHidden" />
        <input type="hidden" name="isActive" id="IsActiveHidden" />
        <input type="hidden" name="partsCategoryID" id="partsCatrgoryIDHidden" />
        <input type="hidden" name="partsSupplierID" id="partsSupplierIDHidden" />
        <input type="hidden" name="partsModelID" id="partsModelIDHidden" />
        <input type="hidden" name="wisetechNO" id="txt_WisetechPartsNOHidden" />
        <input type="hidden" name="supplierNO" id="txt_SupplierPartsNOHidden" />
        <input type="hidden" name="procurementProceStart" id="txt_ProcurementPriceStartHidden" />
        <input type="hidden" name="procurementProceEnd" id="txt_ProcurementPriceEndHidden" />
        <input type="hidden" name="marketPriceStart" id="txt_MarketPriceStartHidden" />
        <input type="hidden" name="marketPriceEnd" id="txt_MarketPriceEndHidden" />

        <input type="hidden" name="stockQtyStart" id="txt_StockQuantityStartHidden" />
        <input type="hidden" name="stockQtyEnd" id="txt_StockQuantityEndHidden" />
    </form>
    <iframe id="excelIFrame" name="excelIFrame" style="display: none;"></iframe>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        var PartsModelGrid = mini.get("PartsModelGrid");
        grid.sortBy("ID", "DESC");
        grid.load();
        var PartsModelForm = document.getElementById("PartsModelForm");
        function HideDetail() {
            PartsModelForm.style.display = "none";
        }
        //清空条件
        function clear() {
            mini.get("txt_KeyValue").setValue("");
            mini.getbyName("IsActive").setValue("");
            mini.get("partsCatrgoryID").setValue("");
            mini.get("partsCatrgoryID").setText("");
            mini.get("partsSupplierID").setValue("");
            mini.get("partsSupplierID").setText("");//
            mini.get("partsModelID").setValue("");
            mini.get("partsModelID").setText("");//
            mini.get("txt_WisetechPartsNO").setValue("");
            mini.get("txt_SupplierPartsNO").setValue("");
            mini.get("txt_ProcurementPriceStart").setValue("");
            mini.get("txt_ProcurementPriceEnd").setValue("");
            mini.get("txt_MarketPriceStart").setValue("");
            mini.get("txt_MarketPriceEnd").setValue("");
            mini.get("txt_StockQuantityStart").setValue("");
            mini.get("txt_StockQuantityEnd").setValue("");


        }
        //查询
        function searchList() {
            var keyValue = mini.get("txt_KeyValue").getValue();
            var isActive = mini.getbyName("IsActive").getValue();
            var partsCategoryID = mini.get("partsCatrgoryID").getValue();
            var partsSupplierID = mini.get("partsSupplierID").getValue();
            var partsModelID = mini.get("partsModelID").getValue();
            var wisetechNO = mini.get("txt_WisetechPartsNO").getValue();
            var supplierNO = mini.get("txt_SupplierPartsNO").getValue();
            var procurementProceStart = mini.get("txt_ProcurementPriceStart").getValue();
            var procurementProceEnd = mini.get("txt_ProcurementPriceEnd").getValue();
            var marketPriceStart = mini.get("txt_MarketPriceStart").getValue();
            var marketPriceEnd = mini.get("txt_MarketPriceEnd").getValue();
            var stockQtyStart = mini.get("txt_StockQuantityStart").getValue();
            var stockQtyEnd = mini.get("txt_StockQuantityEnd").getValue();
            grid.load({
                keyValue: keyValue,
                isActive: isActive,
                partsCategoryID: partsCategoryID,
                partsSupplierID: partsSupplierID,
                partsModelID:partsModelID,
                wisetechNO: wisetechNO,
                supplierNO: supplierNO,
                procurementProceStart: procurementProceStart,
                procurementProceEnd: procurementProceEnd,
                marketPriceStart: marketPriceStart,
                marketPriceEnd: marketPriceEnd,
                stockQtyStart: stockQtyStart,
                stockQtyEnd: stockQtyEnd,
            });
        }
        function reloadData() {
            searchList();
        }
        $("#txt_KeyValue").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                searchList();
            }
        });
        function Remove() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.ID);
                    }
                    var id = ids.join(',');
                    //alert(id);
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "/Ajax/AjaxService.aspx?method=DeleteParts",
                        data: {
                            ids: id
                        },
                        success: function (text) {
                            // mini.alert("操作成功!");
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                mini.alert("请选中一条记录");
            }
        }
        function Edit() {
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "/Parts/PartsEdit.html",
                    title: "编辑",
                    width: 900,
                    height: 600,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "Update", ID: row.ID };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();

                    }
                });

            } else {
                alert("请选中一条记录");
            }
        }
        /**新增*********************************************************************/
        function Add() {
            mini.open({
                url: "/Parts/PartsEdit.html",
                title: "新增", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "Insert" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
        
        function onShowRowDetail(e) {
            var grids = e.sender;
            grids.hideAllRowDetail();
            var row = e.record;
            grids.showRowDetail(row);
            var td = grids.getRowDetailCellEl(row);
            td.appendChild(PartsModelForm);
            if (PartsModelForm.style.display == "block") {
                PartsModelForm.style.display = "none";
            }
            else {
                PartsModelForm.style.display = "block";
                PartsModelGrid.load({
                    PartsID: row.ID
                });
            }
        }
        function addModel(e) {

            var row = grid.getSelected();
            var partsID = row.ID; //PartsID
            mini.open({
                url: "/Parts/pub/SelectPartsModel.html?",
                showMaxButton: false,
                title: "添加适用型号",
                width: 800,
                height: 500,
                onload: function () {
                    //打开子页面时传递参数
                    var iframe = this.getIFrameEl();
                    var data = { MultiSelect: "false" };
                    iframe.contentWindow.SetPara(data);
                },
                ondestroy: function (action) {
                    //返回数据时的操作
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            // var userIDs = "";
                            var modelIds = "";
                            for (var i = 0; i < data.length; i++) {

                                modelIds = data[i].ID + "," + modelIds;
                            }
                            //增加
                            EditPartsModelMapping(partsID, modelIds, "Insert");

                        }

                    }
                    if (action == "clear") {

                    }

                }
            });

        }
        function DelModel() {
            var row = grid.getSelected();
            var partsID = row.ID;

            var detailRows = PartsModelGrid.getSelecteds();
            if (detailRows.length == 0) {
                alert("请先选中要删除的适用型号！");
                return;
            }
            var ids = "";
            for (var i = 0; i < detailRows.length; i++) {
                ids = detailRows[i].ID + "," + ids;
            }
            EditPartsModelMapping(partsID, ids, "Remove");
        }
        function EditPartsModelMapping(partsID, ids, action) {
            $.ajax({
                url: "/Ajax/AjaxService.aspx?method=EditPartsModelMapping",
                data: { partsID: partsID, ids: ids, Action: action },
                cache: false,
                success: function (text) {

                    var o = mini.decode(text);
                    var message = o.res;
                    if (o.error != "") {
                        message += "\r\n" + "错误信息：" + o.error;
                        mini.alert(message);
                    }

                    PartsModelGrid.load({ PartsID: partsID });

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert(jqXHR.responseText);
                }
            });
        }
        function onSelectCategory(e) {
            var btnEdit = this;
            var parentID = btnEdit.getValue();
            mini.open({
                url: "/Parts/pub/SelectCategory.html",
                showMaxButton: false,
                title: "选择分类",
                width: 350,
                height: 450,
                onload: function () {
                    var iframe = this.getIFrameEl();

                    if (parentID != "") {
                        iframe.contentWindow.SetDefaultSelect({ ParentID: parentID });
                    }
                },
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            btnEdit.setValue(data.ID);
                            btnEdit.setText(data.CategoryDisplayName);
                        }
                    }
                    if (action == "clear") {
                        btnEdit.setValue("");
                        btnEdit.setText("");
                    }

                }
            });
        }
        function onSelectModel(e) {
            var btnEdit = this;
            mini.open({
                url: "/Parts/pub/SelectPartsModel.html?",
                showMaxButton: false,
                title: "选择机型",
                width: 800,
                height: 500,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            btnEdit.setValue(data[0].ID);
                            btnEdit.setText(data[0].ModelName);
                        }
                    }
                    if (action == "clear") {
                        btnEdit.setValue("");
                        btnEdit.setText("");
                    }

                }
            });
        }
        function onSelectPartsSupplier(e) {
            var btnEdit = this;
            mini.open({
                url: "/Parts/pub/SelectPartsSupplier.html?",
                showMaxButton: false,
                title: "选择供应商",
                width: 800,
                height: 500,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            btnEdit.setValue(data[0].ID);
                            btnEdit.setText(data[0].SupplierName);
                        }
                    }
                    if (action == "clear") {
                        btnEdit.setValue("");
                        btnEdit.setText("");
                    }

                }
            });
        }
        //导出表格
        function ExportExcel() {
            var columns = grid.getBottomColumns();

            function getColumns(columns) {
                columns = columns.clone();
                for (var i = columns.length - 1; i >= 0; i--) {
                    var column = columns[i];
                    if (!column.field) {
                        columns.removeAt(i);
                    } else {
                        var c = { header: column.header, field: column.field };
                        columns[i] = c;
                    }
                }
                return columns;
            }
            var columns = getColumns(columns);
            var json = mini.encode(columns);
            document.getElementById("excelData").value = json;

            // 隐藏域
            var keyValue = mini.get("txt_KeyValue").getValue();
            document.getElementById("txt_KeyValueHidden").value = keyValue;
            var isActive = mini.getbyName("IsActive").getValue();
            document.getElementById("IsActiveHidden").value = isActive;
            var partsCategoryID = mini.get("partsCatrgoryID").getValue();
            document.getElementById("partsCatrgoryIDHidden").value = partsCategoryID;
            var partsSupplierID = mini.get("partsSupplierID").getValue();
            document.getElementById("partsSupplierIDHidden").value = partsSupplierID;
            var partsModelID = mini.get("partsModelID").getValue();
            document.getElementById("partsModelIDHidden").value = partsModelID;
            var wisetechNO = mini.get("txt_WisetechPartsNO").getValue();
            document.getElementById("txt_WisetechPartsNOHidden").value = wisetechNO;
            var supplierNO = mini.get("txt_SupplierPartsNO").getValue();
            document.getElementById("txt_SupplierPartsNOHidden").value = supplierNO;
            var procurementProceStart = mini.get("txt_ProcurementPriceStart").getValue();
            document.getElementById("txt_ProcurementPriceStartHidden").value = procurementProceStart;
            var procurementProceEnd = mini.get("txt_ProcurementPriceEnd").getValue();
            document.getElementById("txt_ProcurementPriceEndHidden").value = procurementProceEnd;
            var marketPriceStart = mini.get("txt_MarketPriceStart").getValue();
            document.getElementById("txt_MarketPriceStartHidden").value = marketPriceStart;
            var marketPriceEnd = mini.get("txt_MarketPriceEnd").getValue();
            document.getElementById("txt_MarketPriceEndHidden").value = marketPriceEnd;
            var stockQtyStart = mini.get("txt_StockQuantityStart").getValue();
            document.getElementById("txt_StockQuantityStartHidden").value = stockQtyStart;
            var stockQtyEnd = mini.get("txt_StockQuantityEnd").getValue();
            document.getElementById("txt_StockQuantityEndHidden").value = stockQtyEnd;

            var excelForm = document.getElementById("excelForm");
            excelForm.submit();
        }
    </script>
</body>
</html>
